#!/bin/sh
echo $0 $*
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}

# 修改为直接获取文件夹名称的用法,不同游戏文件名不同
GAMEDIR="/mnt/SDCARD/Ports/Half-Life"
# GAMEDIR=${PWD}
echo ==========GAMEDIR is $GAMEDIR
controlfolder="../PortMaster"

source $controlfolder/control.txt
#source $controlfolder/tasksetter

get_controls

# 增加错误输出记录
exec > >(tee "$GAMEDIR/log.txt") 2>&1
cd $GAMEDIR

$ESUDO chmod 666 /dev/uinput

$GPTOKEYB "hode" -c $GAMEDIR/hode.gptk &

if [[ -e "/usr/share/plymouth/themes/text.plymouth" ]]; then
	SDL_GAMECONTROLLERCONFIG="$sdl_controllerconfig" LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0.10.0 ./hode 2>&1 | tee ./log.txt
else
	SDL_GAMECONTROLLERCONFIG="$sdl_controllerconfig" ./hode 2>&1 | tee ./log.txt
fi
$ESUDO kill -9 $(pidof gptokeyb)
$ESUDO systemctl restart oga_events &
printf "\033c" > /dev/tty1